<?php
// +----------------------------------------------------------------------
// | 分销联盟-申请加入
// +----------------------------------------------------------------------
// | Author: TongBC <501468940@qq.com>
// +----------------------------------------------------------------------
// | Date  : 2015/03/06
// +----------------------------------------------------------------------
include_once("common/header.html");
include_once("common/left.html");
include_once("class/MemberAccount.class.php");
include_once("class/Alliance.class.php");

if($_SESSION['alliance']) exit('联盟禁止加入别的联盟');
$mid = $_SESSION['sid'];
$aid = $_REQUEST['aid'];
$aid = 1;

$mem = new \pft\Member\MemberAccount($GLOBALS['le']);
$m_info = $mem->GetOne($mid);
$sql="select id,dtitle,dstatus,protocol from `pft_distributor_union_SE` where id=$aid limit 1";
$GLOBALS['le']->query($sql);
$a_info = $GLOBALS['le']->fetch_assoc();


// 获取所有联盟
if(isset($_REQUEST['id']) && $_REQUEST['id']==4){
	$alliance_id = $_REQUEST['id']+0;
	$sql = "select id,dtitle,fid from `pft_distributor_union_SE` where fid=3779 and dstatus=0";
	$GLOBALS['le']->query($sql);
	$dbRow = $GLOBALS['le']->fetch_assoc();
	if(count(dbRow)==0) exit('联盟不存在或已解散');
	$als[0] = $dbRow;
}else{
	$sql = "select id,dtitle,fid from `pft_distributor_union_SE` where dstatus=0";
	$GLOBALS['le']->query($sql);
	while($rows = $GLOBALS['le']->fetch_assoc()) $als[] = $rows;
}


// 默认选中角色
$checked_dis = '';
$checked_sup = '';
if(isset($_REQUEST['id'])) $checked_sup = 'checked="checked"';


// 页面变量
$uid = $a_info['id'];// 联盟ID
$mid = $_SESSION['sid'];// 会员ID
$name = $a_info['dtitle'];// 联盟名称
$dname = $m_info['dname'];


?>
<link rel="stylesheet" href="http://www.12301.cc/css/common/www.12301.cc.global.css"/>
<!--<script type="text/javascript" src="http://www.12301.cc/js/plugin/json2.js"></script>-->
<!--[if lt IE 7]><div id="allianceMod" class="lt-ie10 lt-ie9 lt-ie8 lt-ie7 ie6 allianceMod"> <![endif]-->
<!--[if IE 7]><div id="allianceMod" class="lt-ie10 lt-ie9 lt-ie8 ie7 allianceMod"> <![endif]-->
<!--[if IE 8]><div id="allianceMod" class="lt-ie10 lt-ie9 ie8 allianceMod"> <![endif]-->
<!--[if IE 9]><div id="allianceMod" class="lt-ie10 ie9 allianceMod"><![endif]-->
<!--[if gt IE 9]><!--><div id="allianceMod" class="allianceMod"> <!--<![endif]-->
<style type="text/css"> 
.allianceMod .pgIcon.add{ top:2px; margin-right:2px;}
.allianceMod{ width:800px; float:right; font-family:'Avenir Next',Avenir,'Helvetica Neue',Helvetica,'Lantinghei SC','Hiragino Sans GB','Microsoft YaHei',"微软雅黑",STHeiti,'WenQuanYi Micro Hei',SimSun,sans-serif}
.allianceMod .textInp{ height:26px; line-height:26px; border:1px solid #e5e5e5; padding:3px 5px; background:#fcfcfc}
.allianceMod .tabPannel{ display:none}
.allianceMod .tabPannel .saveBtn{ display:block; width:160px; height:34px; line-height:34px; margin:50px auto; color:#fff; text-align:center; background:#098bc6;}
.allianceMod .tabPannel .save{ display:block; cursor:not-allowed;width:160px; height:34px; line-height:34px; margin:50px auto; color:#fff; text-align:center; background:#E5E5E5;}
.allianceMod .tabPannel .saveBtn:hover{ text-decoration:none; background:#098bc6}
.allianceMod .tabHead{ padding-left:15px; overflow:hidden; border-bottom:2px solid #019be1}
.allianceMod .tabHead li{ float:left; height:36px; line-height:36px; padding:0 25px; cursor:pointer; border-top-left-radius:2px; border-top-right-radius:2px;}
.allianceMod .tabHead li.active{ background:#019be1; color:#fff}
.allianceMod .tabPannel.profit .con{ padding:15px; padding-left:35px;  background:#fafafa; }
.allianceMod .tabPannel.profit .con select{ width:568px;height:35px;line-height:35px;margin-left: 16px; border:1px solid #e5e5e5; }
.allianceMod .tabPannel.profit .con span.lt {width: 60px;display: inline-block;float: left;text-align:left;margin-top: 10px;}
.allianceMod .tabPannel.profit .con textarea{ width:545px;height:400px;padding:10px;cursor:not-allowed;overflow-y:auto;  background:#fafafa; resize: none;text-align: left;border:1px solid #e5e5e5;margin-left: 16px;}
.allianceMod .tabPannel.profit .spcon{ display:inline-block; width:485px; margin-left:16px}
.allianceMod .tabPannel.profit .spcon.last{ margin-left:0px} 
.allianceMod .tabPannel.profit .textInp{ width:50px; margin:0 4px}
.allianceMod .tabPannel.profit .checked{ width: 20px;margin-left: 16px;height: 15px;margin-top: 10px;}
.allianceMod .tabPannel.profit .textInp.name{ width:556px; text-align:left; margin-left:16px;}
.allianceMod .line{ margin-top:13px;}
.allianceMod .line .textInp{ text-align:center; background:#fff}
.allianceMod .line .group{ margin-right:5px;}
.allianceMod .line .lt{ font-weight:bold}
p.checkbox {width: 100px;float: left;margin-left: 110px;}
p.money{display:inline-block;width:100px;height:40px;line-height:40px;  margin-left: 20px;}
</style>
<input name="" id="alliance_uid" type="hidden" value="<?=$uid?>"/>
<ul id="tabHead" class="tabHead clearfix"><li class="profit active">加入联盟申请表</li></ul>
<form action="" id="alliance_join_d" method="post">
<input type="hidden" name="action" value="apply_union" />
<div id="profitPannel" class="tabPannel profit" style="display:block">
	<div class="con">
		<span class="lt">甲方：</span>
		<select class="select" name="aid" id="change">
			<?foreach($als as $data):?>
				<option value="<?=$data['id']?>"><?=$data['dtitle']?></option>
			<?endforeach;?>
		</select>
	</div>
	<div class="con">
		<span class="lt">乙方：</span>
		<input type="text" value="<?=$dname?>" class="textInp name" disabled="true"/>
	</div>
	<div class="con">
		<span class="lt">押金</span>
		<p class="money">供销押金：2</p>
		<p class="money">供应押金：1</p>
		<p class="money">分销押金 ：1</p>
	</div>
	<div class="con">
		<span class="lt">我要：</span>
		<input type="checkbox" name="us" class="checked" value="1" <?=$checked_sup?>/><i>供应产品</i>
		<input type="checkbox" name="ud" class="checked" value="1" <?=$checked_dis?>/>销售产品
	</div>
	<div class="con">
		<span class="lt">联盟协议：</span>
		<textarea id="textarea" disabled="disabled"></textarea>
	</div>
	<div class="con">
		<p class="checkbox"><input type="checkbox" id="check" name="pto" value="1" >同意联盟协议</p>
	</div>
	
	<a class="save" href="#">提交</a>
</div>
</form>
<div class="tabPannel citydai"></div>
</div>
<script type="text/javascript" src="http://www.12301.cc/js/global/www.12301.cc.global.js"></script>
<script type="text/javascript">
$("#check").on("click",function() {
	if ($("#check").attr("checked") == "checked"){
	$(".save").css("background","#098bc6");
	$(".save").css("cursor","auto"); 
	$(".save").addClass("saveBtn");
	} 
	else if($("#check").attr("checked") != "checked"){
	$(".save").css("background","#E5E5E5");
	$(".save").css("cursor","not-allowed"); 
	$(".save").removeClass("saveBtn");
	}
})
$(".saveBtn").live("click",function() {
	// $("form").submit();
	var postData =  $("form#alliance_join_d").serialize();
	 $.ajax({
        type:'POST',
        url: 'call/jh_alliance_dev.php',
        data: postData,
        dataType:'json',
        success: function(result){
            if(result.status=='success') {
               alert(result.mesg);
			   location.href = 'http://www.12301.cc/plist.html';
            } else if(result.code=='101'){
				if(confirm("您尚未进行资质认证，请前往进行认证")){
					location.href ="http://www.12301.cc/certifi.html"; 
				}
               // alert(result.mesg);
            }
			else{
				alert(result.mesg);
			}
        },
})
});

$("#change").on("change",function(){
	var option_val = $(this).val();
	$.getJSON('http://www.12301.cc/call/jh_alliance.php', {
					action:'infomation',
					aid:option_val
				},function(data){
				if(data.code == '100'){
                    constuc(data);
				}
				else{
					alert("请求联盟协议失败")
				}
			})
});
window.onload = function() { 
	var option_val = $("#change").val();
	$.getJSON('http://www.12301.cc/call/jh_alliance.php', {
					action:'infomation',
					aid:option_val
				},function(data){
				if(data.code == '100'){
                    constuc(data);
				}
				else{
					alert("请求联盟协议失败")
				}
			})
};

 function constuc(data){
     $("#textarea").html(data.data['protocol']);
     var ya = $("div#profitPannel div:eq(2)");
     var ya0 =data.data.cash_pledge0;
     var ya1 =data.data.cash_pledge1;
     var ya2 =data.data.cash_pledge2;
     ya.children('p:eq(0)').text('供销押金'+ya0);
     ya.children('p:eq(1)').text('供应押金'+ya1);
     ya.children('p:eq(2)').text('分销押金'+ya2);
 }
</script>
<?
include("common/footer.html");
?>